package com.zhg.javakc.modules.materials.service;

import com.zhg.javakc.base.page.Page;
import com.zhg.javakc.base.service.BaseService;
import com.zhg.javakc.modules.masterialstype.dao.TypeDao;
import com.zhg.javakc.modules.materials.dao.MaterialsDao;
import com.zhg.javakc.modules.materials.entity.MaterialsEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class MaterialsService  extends BaseService<MaterialsDao,MaterialsEntity> {
    @Autowired
    private MaterialsDao materialsDao;
    @Autowired
    private TypeDao typeDao;
    public Page<MaterialsEntity> queryMasterials(MaterialsEntity entity,HttpServletRequest request,HttpServletResponse response){
        Page<MaterialsEntity> page=new Page(request,response);
        entity.setPage(page);
        List<MaterialsEntity> list= materialsDao.findList(entity);
        page.setList(list);
        return page;
    }
    public List<Map<String,Object>> queryGrand(String gamTypeId){
        List<Map<String,Object>> list=new ArrayList<>();
        Map<String,Object> map=typeDao.queryGrand(gamTypeId);
        Map<String,Object> map2=typeDao.queryGrand( map.get("pId").toString());
        list.add(map2);
        Map<String,Object> map3=typeDao.queryGrand( map2.get("pId").toString());
        list.add(map3);
       return  list;
    }

    public void updateStop(String gamId){
        materialsDao.updateStop(gamId);

    }
    public void updateStart(String gamId){
        materialsDao.updateStart(gamId);

    }

    public Page<MaterialsEntity> queryByStatus(MaterialsEntity entity,HttpServletRequest request,HttpServletResponse response){
        Page<MaterialsEntity> page=new Page(request,response);
        entity.setPage(page);
        List<MaterialsEntity> list= materialsDao.queryByStatus(entity);
        page.setList(list);
        return page;
    }
}
